package com.mgq.juc.threadpool;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.SynchronousQueue;

/**
 * @author MaGuangQi
 * SynchronousQueue
 * @date 2021-12-22 10:07
 **/
@Slf4j
public class TestSynchronousQueue {
    public static void main(String[] args) throws InterruptedException {
        SynchronousQueue<String> queue = new SynchronousQueue<>();
        new Thread(()->{
            try {
                log.debug("putting 1.........");
                queue.put("1");
                log.debug("end  1.........");
                log.debug("putting 2.........");
                queue.put("2");
                log.debug("end  2.........");
                log.debug("putting 3.........");
                queue.put("3");
                log.debug("end  3.........");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"线程1").start();
        Thread.sleep(2000);
        new Thread(()->{
            try {
                String str = queue.take();
                log.debug("获取到值,{}",str);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"线程2").start();
        Thread.sleep(1000);
        new Thread(()->{
            try {
                String str = queue.take();
                log.debug("获取到值,{}",str);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"线程3").start();
    }
}
